﻿
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;

using Swaf;
using Swaf.BizObj;
using Swaf.BizRule;

namespace GoogleMap
{
	public class GoogleMapBizRule : BaseBizRule
	{
		public string getGoogleMapCompanySettingsTemplate(IApplication app, IRuleContext context, object resultValue, object[] inputParams)
		{
			return resultValue.ToString() + ",GoogleMap.Gui.AspNet.GoogleMapSettingsDisplay";
		}
		public IBizObjList getGoogleMapCompanySettingsDbFields(IApplication app, IRuleContext context, object resultValue, object[] inputParams)
		{
			IBizObjList settingsFields = resultValue as IBizObjList;

			IBizObj analytics = settingsFields.insertNew();
			analytics.put("dbName", "googleMapKey");
			analytics.put("bizObjName", "googleMapKey");
			analytics.put("aliasName", "googleMapKey");
			analytics.put("dbType", "UniCodeVarChar");

			return settingsFields;
		}

		//Globe will give NMEA format of lat/lng.  We need to call this to convert to location that can
		//be used in google map.
		public string convertNmeaToWgs84(string nmea)
		{
			var str = nmea.Substring(0, nmea.Length-1);
			string deg = str.Substring(0, 2); // 013
			string min = str.Substring(2); // 38.7008
			string due = nmea.Substring(nmea.Length-1).ToUpper();

	        float ret = Int32.Parse(deg) + (float.Parse(min) / 60);
			if("E".CompareTo(due)==0 || "N".CompareTo(due)==0)
				return ret.ToString();
			else 
				return (-ret).ToString();
 		}
	}
}

